<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next"></script>
    <style>
        .box {
            width: 300px;
            height: 100px;
            background-color: teal;
            font-size: 30px;
        }
    </style>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    const demo = {
        props: {
            'count': {
                //设置传入的数据类型，若类型不一致则警告
                type: Number,
                //是否必须传入数据
                required: true,
                //设置默认值
                default: function () {
                    return 10
                },
                // 验证传入的值是否符合要求
                validator: function (value) {
                    return value < 1
                }
            }
        },
        template: `
                <div class="box">
                    {{count}}
                </div>
                <button @click="handle">点我</button>
                `,
        methods: {
            handle () {
                this.$emit('gotoFather', 5)//可传参，在父组件的事件处理函数添加形参接收
            }
        }

    }
    let vm = {
        data () {
            return {
                count: 0,
            }
        },
        components: {
            demo
        },
        template: `<div>
                        <demo 
                        :count="count" 
                        @gotoFather="handleCount"></demo>
                    </div>
                    `,
        methods: {
            handleCount (e) {
                this.count += e
            }
        }
    }
    Vue.createApp(vm).mount('#app')
</script>

</html>